//
// File:	Inputs.hpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Create:	30/01/2010 at 05:14:20
// Purpose:	
//
#ifndef INPUTS_HPP
#define INPUTS_HPP

#include <SFML/Window.hpp>
#include "Base.hpp"
#include "Input.hpp"
#include "DisplayManager.hpp"

//------------------------------------------------------------------
// Basic Input
//------------------------------------------------------------------
template <typename T>
class BasicInput : public Input<T>
{
public:
	typedef	std::map<std::string, T>				BindingMapType;

	void											Update()
	{
		DisplayManager *pDisplayManager = dynamic_cast<DisplayManager *>(&GlobalVariables::DisplayManager::Get());
		if (pDisplayManager == NULL)
			return;
		RenderCanvas *pRenderCanvas = dynamic_cast<RenderCanvas *>(pDisplayManager->GetRenderCanvas());
		if (pRenderCanvas == NULL)
			return;
		InputNamesMap::iterator nameIter = m_inputNames.begin();
		InputNamesMap::iterator nameEndIter = m_inputNames.end();
		for (; nameIter != nameEndIter; ++nameIter)
		{
			InputMap::iterator inputIter = nameIter->second.begin();
			InputMap::iterator inputEndIter = nameIter->second.end();
			for (; inputIter != inputEndIter; ++inputIter)
			{
				inputIter->second = HasInput(pRenderCanvas, inputIter->first);
			}
		}
	}
	virtual bool											HasInput(RenderCanvas *, T) const = 0;
	static const std::map<std::string, T>					&GetBindingNames();
};

//------------------------------------------------------------------
// Keyboard
//------------------------------------------------------------------
class InputKeyboard : public BasicInput<sf::Key::Code>
{
public:
	bool							HasInput(RenderCanvas *pRenderCanvas, sf::Key::Code keyCode) const;
	static const BindingMapType		&GetBindingNames();
};

//------------------------------------------------------------------
// Mouse
//------------------------------------------------------------------
class InputMouse : public BasicInput<sf::Mouse::Button>
{
public:
	bool						HasInput(RenderCanvas *pRenderCanvas, sf::Mouse::Button mouseButton) const;
	static const BindingMapType	&GetBindingNames();
};

#endif //!INPUTS_HPP
